package com.baizhi.cmfz.test;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import com.baizhi.cmfz.CmfzApplication;
import com.baizhi.cmfz.entity.Guru;
import com.baizhi.cmfz.service.GuruService;
import org.apache.poi.ss.usermodel.Workbook;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.List;
import java.util.Map;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = CmfzApplication.class)
public class esayPoi {
    @Autowired
    private GuruService guruService;
    @Test
    public void testPoi() throws Exception{
        ExportParams exportParams = new ExportParams("上师数据", "guru");
        Map map=guruService.showAllGuru(1,20);
        List<Guru> list= (List<Guru>) map.get("data");
        Workbook workbook = ExcelExportUtil.exportExcel(exportParams,
                Guru.class, list);
        workbook.write(new FileOutputStream("E://easy.xls"));
    }
    @Test
    public void test2() throws Exception {
        ImportParams importParams=new ImportParams();
        importParams.setTitleRows(1);
        importParams.setHeadRows(1);
        List<Guru> list= ExcelImportUtil.importExcel(new FileInputStream("E://easy.xls"),Guru.class,importParams);
        for(Guru guru:list){
            System.out.println(guru);
        }
    }
}
